<template>
	<view class="wrap">
		<u-navbar :title="$t('clsz')" title-width="340" :border-bottom="false" back-icon-color="#fff" title-color="#fff" :background="{ backgroundColor: '#0030A8' }"></u-navbar>
		<view class="tom-container">
			<view class="list">
				<view class="nr_top">
					<view class="right">
						<view class="right_xin" style="margin-bottom: 40upx;">
							<view class="right_xin_left">{{$t('jys')}}</view>
							<view class="right_xin_right">
								<view class="label" @tap="Select_Ro2">{{ pageData.exchangeName }}</view>
								<u-icon name="you" custom-prefix="custom-icon" size="20"></u-icon>
							</view>
						</view>
						<view class="right_xin">
							<view class="right_xin_left">{{$t('hylx')}}</view>
							<view class="right_xin_right">
								<view class="label" @tap="Select_Ro3">{{ contractType[contractType_index].label }}</view>
								<u-icon name="you" custom-prefix="custom-icon" size="20"></u-icon>
							</view>
						</view>
					</view>
				</view>
				<view class="nr_item" style="align-items: flex-start;">
					<view class="nr_item_left">{{$t('clxz')}}：</view>
					<view class="nr_item_right">
						<view class="strategy">
							<view class="strategy-item" :class="{ active: pageData.dangerType == 'STEADY' }">
								{{$t('bsx')}}
								<u-icon name="wenhao" custom-prefix="custom-icon" size="30" style="margin-left: 16rpx;" @tap="Strategy_tips(1)"></u-icon>
							</view>
							<view class="strategy-item" :class="{ active: pageData.dangerType == 'RADICAL' }">
								{{$t('jjx')}}
								<u-icon name="wenhao" custom-prefix="custom-icon" size="30" style="margin-left: 16rpx;" @tap="Strategy_tips(2)"></u-icon>
							</view>
							<view class="strategy-item" :class="{ active: pageData.dangerType == 'RISK_CONTROL_STEADY' }" v-if="pageData.dangerType =='RISK_CONTROL_STEADY' || pageData.dangerType =='RISK_CONTROL_RADICAL'">
								{{$t('fkbs')}}
								<u-icon name="wenhao" custom-prefix="custom-icon" size="30" style="margin-left: 16rpx;" @tap="Strategy_tips2(1)"></u-icon>
							</view>
							<view class="strategy-item" :class="{ active: pageData.dangerType == 'RISK_CONTROL_RADICAL' }" v-if="pageData.dangerType =='RISK_CONTROL_STEADY' || pageData.dangerType =='RISK_CONTROL_RADICAL'" style="margin-top: 10rpx;">
								{{$t('fkjj')}}
								<u-icon name="wenhao" custom-prefix="custom-icon" size="30" style="margin-left: 16rpx;" @tap="Strategy_tips2(2)"></u-icon>
							</view>
						</view>
					</view>
				</view>
				<view class="nr_item nr_item_border">
					<view class="nr_item_left">{{$t('clid')}}：</view>
					<view class="nr_item_right">
						<view class="nr_item_right_id">
							{{ pageData.id }}
							<u-icon name="fuzhi" custom-prefix="custom-icon" size="28" @tap="copy(pageData.tacticsId)" style="margin-left: 16rpx;"></u-icon>
						</view>
					</view>
				</view>
				<view class="nr_item nr_item_border" style="align-items:flex-start;">
					<view class="nr_item_left">{{$t('zdhc')}}：</view>
					<view class="nr_item_right">
						<view class="limit">
							<input class="limit-input" type="digit" v-model="form.stopLoss" :placeholder="$t('qsrzdhc')" maxlength="10" @blur="inputStopLoss" />
							<text class="limit-text">{{ $BigNumber(form.stopLoss || 0).multipliedBy(100) }}%</text>
						</view>
						<view class="Opening_amount" v-if="Number(form.stopLoss) > pageData.stopLossRange[1]">{{$t('zdhc')}}{{ pageData.stopLossRange[1] }}</view>
						<view class="Opening_amount" v-if="Number(form.stopLoss) < pageData.stopLossRange[0]">{{$t('zxhc')}}{{ pageData.stopLossRange[0] }}</view>
					</view>
				</view>
				<view class="nr_item nr_item_border" style="align-items:flex-start;">
					<view class="nr_item_left">{{$t('hzxh')}}：</view>
					<view class="nr_item_right">
						<view class="limit">
							<input class="limit-input" type="digit" v-model="form.transferAmount" :placeholder="$t('qsrhzxh')" maxlength="10" @blur="inputTransferAmount" />
							<text class="limit-text">USDT</text>
						</view>
						<view class="Opening_amount" v-if="Number(form.transferAmount) < Number(pageData.transferAmountMin)">
							{{$t('yljezdsz')}}{{ pageData.transferAmountMin }}U
						</view>
					</view>
				</view>
				<view class="nr_item" v-if="pageData.dangerType !='RISK_CONTROL_STEADY' && pageData.dangerType !='RISK_CONTROL_RADICAL'">
					<view class="nr_item_left">{{$t('bz1')}}：</view>
					<view class="nr_item_right">
						<view class="select_for" @tap="Select_Ro5">
							{{ exchangeCoin[0] }}
							<!-- <u-icon name="you" custom-prefix="custom-icon" size="20"></u-icon> -->
							<!-- <text class="limit-text">{{ $BigNumber(pageData.executeTimes).multipliedBy(100) }}%</text> -->
						</view>
					</view>
				</view>
				<view class="nr_item" v-if="pageData.dangerType !='RISK_CONTROL_STEADY' && pageData.dangerType !='RISK_CONTROL_RADICAL'">
					<view class="nr_item_left">{{$t('bz2')}}：</view>
					<view class="nr_item_right">
						<view class="select_for" @tap="Select_Ro6">
							{{ exchangeCoin[1]  }}
							<!-- <u-icon name="you" custom-prefix="custom-icon" size="20"></u-icon> -->
							<!-- <text class="limit-text">{{ $BigNumber(pageData.executeTimes).multipliedBy(100) }}%</text> -->
						</view>
					</view>
				</view>
				<view class="nr_item">
					<view class="nr_item_left">{{$t('xhfs')}}：</view>
					<view class="nr_item_right">
						<view class="select_for" @tap="Select_Ro4">
							{{ tacticsType[tacticsType_index].label }}
							<u-icon name="you" custom-prefix="custom-icon" size="20"></u-icon>
						</view>
					</view>
				</view>
				<view class="nr_item">
					<view class="nr_item_left">{{$t('kyye')}}：</view>
					<view class="nr_item_right">
						<view class="exchange_Balance">
							{{ pageData.exchangeBalance }}
							<text class="text">USDT</text>
						</view>
					</view>
				</view>
				<view class="nr_item" style="border-bottom: 2rpx solid #f5f5f5;">
					<view class="nr_item_left">{{$t('ggbs')}}：</view>
					<view class="nr_item_right">
						<view class="exchange_Balance">{{ leverage }}</view>
					</view>
				</view>
				<view class="btn_success" @tap="btn_ok"><text class="text">{{$t('qdxg')}}</text></view>
			</view>
		</view>
		<u-picker v-model="show2" mode="selector" :range="list2" range-key="label" ></u-picker>
		<u-picker v-model="show3" mode="selector" :range="contractType" @confirm="picker_confirm3" range-key="label"></u-picker>
		<u-picker v-model="show4" mode="selector" :range="tacticsType" @confirm="picker_confirm4" range-key="label"></u-picker>
		<u-toast ref="uToast" />
		<tom-pwd v-if="showPwd" @cancel="showPwd = false" @confirm="confirm"></tom-pwd>
	</view>
</template>

<script>
export default {
	data() {
		return {
			id: '',
			list2: [
				{
					value: '',
					label: ''
				}
			],
			contractType: [
				/*合约类型*/
				{
					value: '',
					label: ''
				}
			],
			tacticsType: [
				/*循环方式*/
				{
					value: '',
					label: ''
				}
			],
			exchangeNameList2_Index : 0,
			contractType_index: 0,
			tacticsType_index: 0,
			show2: false,
			show3: false,
			show4: false,
			form: {
				stopLoss: '' /*最大回撤*/,
				transferAmount: '' /*划转现货*/
			},
			showPwd: false /*密码输入状态*/,
			// 策略选择列表
			strategyList: [{ label: this.$t('bsx'), value: 'SHOCK_STEADY', value2: 'STEADY' }, { label: this.$t('jjx'), value: 'SHOCK_RADICAL', value2: 'RADICAL' }],
			// 选中策略索引
			strategy: 0,
			pageData: { stopLossRange: [0, 0] },
			strings: '' /*开通须知*/,
			leverage: '', /*杠杆倍数*/
			exchangeCoin:[],
		};
	},
	onLoad(id) {
		console.log(id);
		this.id = id.id;
	},
	onShow() {
		this.indexData();
	},
	mounted() {
		this.show = true;
	},
	methods: {
		indexData() {
			uni.showLoading({
				mask: true,
				title: this.$t('loading.title')
			});
			this.$api.consoleApi
				.shock_getContractRobotModifyPage({
					tacticsId: this.id
				})
				.then(res => {
					this.pageData = res.data;
					this.leverage = res.data.leverage;
					this.form.stopLoss = res.data.stopLoss;
					this.form.transferAmount = res.data.transferAmount;
					this.tacticsType_index = res.data.tacticsType == 1 ? 1 : 0;
					this.exchangeNameList2_Index = res.data.exchangeName == this.$t('oyjys') ? 0 : 1;
					this.exchangeCoin = res.data.exchangeCoin.split(',');
					this.list2 = [{value: '0',label: res.data.exchangeName}];
					res.data.dangerType == 'STEADY' ? this.strategy = 0 : this.strategy = 1
					var arr2 = [];
					var arr3 = [];
					res.data.contractType.forEach(function(item) {
						arr2.push({ value: item, label: item });
					});
					res.data.tacticsTypes.forEach(function(item, index) {
						arr3.push({ value: index, label: item });
					});
					this.contractType = arr2;
					this.tacticsType = arr3;
					console.log(arr1);
					uni.hideLoading();
				})
				.catch(res => {
					uni.hideLoading();
				});
		},
		Select_Ro2(e) {
			this.show2 = true;
		},
		Select_Ro3(e) {
			this.show3 = true;
		},
		Select_Ro4(e) {
			this.show4 = true;
		},
		picker_confirm3(e) {
			this.contractType_index = e[0];
		},
		picker_confirm4(e) {
			this.tacticsType_index = e[0];
		},
		copy(val) {
			this.$utils.copy(val);
		},
		inputStopLoss() {
			/*回撤验证*/
			if (Number(this.form.stopLoss) < Number(this.pageData.stopLossRange[0])) {
				this.$nextTick(() => {
					this.form.stopLoss = Number(this.pageData.stopLossRange[1]);
					this.$utils.toast(this.$t('zxhc')+`${this.pageData.stopLossRange[0]}`);
				});
			}
			if (Number(this.form.stopLoss) > Number(this.pageData.stopLossRange[1])) {
				this.$nextTick(() => {
					this.form.stopLoss = Number(this.pageData.stopLossRange[1]);
					this.$utils.toast(this.$t('zdhc')+`${this.pageData.stopLossRange[1]}`);
				});
			}
		},
		inputTransferAmount() {
			/*划转现货验证*/
			if (Number(this.form.transferAmount) < this.pageData.transferAmountMin) {
				this.$nextTick(() => {
					this.form.transferAmount = this.pageData.transferAmountMin;
					this.$utils.toast(this.$t('yljezdsz')+`${this.pageData.transferAmountMin}U`);
				});
			}
		},
		switchStrategy(i) {
			/*切换策略*/
		},
		Strategy_tips(e) {
			/*策略详情*/
			this.$refs.uToast.show({
				title: e == 1 ? this.$t('zdkt7') : this.$t('jjkt6'),
				type: 'warning',
				duration: 3000,
				icon: false
			});
		},
		Strategy_tips2(e) {
			/*策略详情*/
			this.$refs.uToast.show({
				title: e == 1? this.$t('fxkzwu'):this.$t('fxjjwu'),
				type: 'warning',
				duration: 3000,
				icon: false
			});
		},
		btn_ok() {
			if (Number(this.form.stopLoss) < Number(this.pageData.stopLossRange[0])) return this.$utils.toast(this.$t('zxhc')+`${this.pageData.stopLossRange[0]}`);
			if (Number(this.form.stopLoss) > Number(this.pageData.stopLossRange[1])) return this.$utils.toast(this.$t('zxhc')+`${this.pageData.stopLossRange[1]}`);
			if (Number(this.form.transferAmount) < this.pageData.transferAmountMin) return this.$utils.toast(this.$t('yljezdsz')+`${this.pageData.transferAmountMin}U`);
			this.showPwd = true;
		},
		confirm(e) {
			this.showPwd = false;
			uni.showLoading({
				mask: true,
				title: this.$t('zztj')
			});
			/*运行机器人接口*/
			this.$api.consoleApi
				.shock_contractRobotModify({
					transferPassword: e,
					id: this.id, //id
					stopLoss: this.form.stopLoss, //回撤比例
					transferAmount: this.form.transferAmount, //回撤比例
					tacticsType: this.tacticsType_index ? '1' : '2' //循环类型，1单次 2循环
				})
				.then(res => {
					this.indexData();
					this.$utils.toast(this.$t('czcg'));
					uni.hideLoading();
				})
				.catch(res => {
					uni.hideLoading();
				});
		}
	}
};
</script>

<style lang="scss" scoped>
.tom-container {
	padding-top: 50rpx;
}
.list {
	flex: 1;
	border-radius: 50rpx 50rpx 0rpx 0rpx;
	overflow: auto;
	background-color: #fff;
	.nr_top {
		padding: $nr-padd;
		border: 2rpx solid $page-bg;
		.right {
			width: 100%;
			.right_xin {
				display: flex;
				justify-content: space-between;
				.right_xin_left {
					color: $tom-text-color;
					font-size: 28rpx;
					font-weight: bold;
				}
				.right_xin_right {
					color: $tom-text-sub-color2;
					display: flex;
					.label {
						font-size: 28rpx;
						margin-right: 20rpx;
					}
					.u-icon {
						transform: rotate(90deg);
					}
				}
			}
		}
	}
	.nr_item {
		padding: 20rpx $nr-padd;
		display: flex;
		align-items: center;
		.nr_item_left {
			white-space: nowrap;
			font-weight: bold;
			font-size: 28rpx;
		}
		.nr_item_right {
			.strategy {
				display: flex;
				flex-wrap: wrap;
				.strategy-item {
					color: $tom-text-sub-color;
					font-size: 28rpx;
					margin: 0px 20rpx;
				}
				.active {
					color: $text-color;
				}
				.strategy-item_plus {
					border: 2rpx solid $text-color;
					padding: 6rpx 20rpx;
					margin-top: -8rpx;
				}
			}
			.select_for {
				display: flex;
				align-items: center;
				font-size: 28rpx;
				.u-icon {
					transform: rotate(90deg);
					margin-left: 10rpx;
				}
			}
			.exchange_Balance {
				color: $text-color;
				font-size: 28rpx;
				font-weight: bold;
				.text {
					margin-left: 10rpx;
					color: $tom-text-color;
					font-weight: 400;
				}
			}
			.Opening_amount {
				font-size: 24rpx;
				color: $text-color;
				margin-top: 10rpx;
			}
			.limit {
				display: flex;
				align-items: center;
				&-input {
					width: 240rpx;
					height: 50rpx;
					border: 1px solid $tom-text-sub-color;
					border-radius: 4rpx;
					color: $text-color;
					font-size: 24rpx;
					padding: 0 20rpx;
					box-sizing: border-box;
				}
				&-text {
					margin-left: 20rpx;
					color: $tom-text-color;
					font-size: 24rpx;
				}
				.buyin-plusreduce {
					margin-left: 30rpx;
					width: 104rpx;
					height: 40rpx;
					padding: 0 10rpx;
					display: flex;
					align-items: center;
					justify-content: space-between;
					border: 1px solid $text-color;
					border-radius: 8rpx;
					.buyin-plusreduce-line {
						width: 1px;
						height: 20rpx;
						background-color: #2a405c;
					}
				}
			}
		}
	}
	.nr_item_border {
		border: none;
	}
	.btn_success {
		width: 240rpx;
		height: 80rpx;
		background-color: $text-color;
		color: #fff;
		display: flex;
		align-items: center;
		justify-content: center;
		border-radius: 10rpx;
		margin: 50rpx auto;
		.text {
			font-size: 32rpx;
			font-weight: bold;
		}
	}
}
.RobotShock_tips {
	padding: $nr-padd;
	.title {
		font-size: 32rpx;
		color: $tom-text-color;
		font-weight: bold;
		margin-bottom: 20rpx;
	}
	.text {
	}
}
.popup {
	.pop_nr {
		display: inline-block;
		width: 598rpx;
		height: 761rpx;
		background-image: url('/static/new_images/RobotShockbg.png');
		background-size: 100% 100%;
		padding-top: 330rpx;
		padding-right: 90rpx;
		padding-bottom: 0rpx;
		padding-left: 90rpx;
		box-sizing: border-box;
		position: relative;
		text-align: center;
		.text2 {
			font-size: 36rpx;
			font-weight: bold;
			color: $tom-text-color;
			margin-bottom: 20rpx;
		}
		.text {
			color: #999;
			font-size: 28rpx;
		}
		.btn {
			width: 500rpx;
			height: 76rpx;
			border-radius: 76rpx;
			position: absolute;
			bottom: 52rpx;
			left: 54rpx;
		}
	}
}
</style>
